package cn.dubito.android_linearing;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lilianghy
 * @description: 管理Activity活动类
 * @datatime 18/2/11 上午11:36
 */

public class ActivityCollector {

    /**
     * activity集合
     */
    public static List<Activity> activities = new ArrayList<>();

    /**
     * 添加活动到集合中
     *
     * @param activity
     */
    public static void addActivity(Activity activity) {
        activities.add(activity);
    }

    /**
     * 销毁指定活动
     * @param activity
     */
    public static void removeActivity(Activity activity) {
        activities.remove(activity);
    }

    /**
     * 销毁全部活动
     */
    public static void finishAll() {
        for (Activity activity : activities) {
            if (!activity.isFinishing()) {
                activity.finish();
            }
        }
    }
}
